package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerListDO;
import com.qk.dto.customer.CustomerListDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customers")
@Slf4j
public class CustomerController {
    @Autowired
    private CustomerService customerService;



    //修改客户
    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return Result.success();
    }


    //客户列表查询
    @GetMapping
    public Result getCustomerList(CustomerListDTO dto){
        PageResult<CustomerListDO> pageResult = customerService.getCustomerList(dto);
        return Result.success(pageResult);
    }


    //添加客户
    @PostMapping
    public Result addCustomer(@RequestBody Customer customer){
        customerService.addCustomer(customer);
        return Result.success();
    }


    //根据id查询客户
    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id){
        Customer customer = customerService.getCustomerById(id);
        return Result.success(customer);
    }



}
